package com.zut.hospital.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.*;

/**
 * @program: hos-test
 * @description: wu
 * @author: 杨曼珍
 * @create: 2019-05-17 15:10
 **/

@Configuration
public class WebConfig implements WebMvcConfigurer {

    /**
     * @param registry
     * @description: 增加视图映射, 将请求映射到指定的视图中
     * @Date: 2019/5/24
     * @Author: zsy
     */


    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        //将所有/static/** 访问都映射到classpath:/static/ 目录下
        registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/");
    }
    @Bean
    LoginInterceptor loginInterceptor() {
        return new LoginInterceptor();
    }


    /**
     * 配置拦截器
     * @author yuqingquan
     * @param registry
     */

    public void addInterceptors(InterceptorRegistry registry) {
        InterceptorRegistration loginRegistry= registry.addInterceptor(loginInterceptor());
        loginRegistry.excludePathPatterns("/html/login.html");
        loginRegistry.excludePathPatterns("/hospital/login");
        loginRegistry.excludePathPatterns("/admin/**");
    }
    @Override
    public void addViewControllers(ViewControllerRegistry registry){
        registry.addRedirectViewController("/","/html/index.html");
    }
}

